package com.fnzx.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.SneakyThrows;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: Wang Zhifu
 * @create: 2021/10/31 14:33
 * @Description: 自动填充字段值
 */
@Component
public class EntityHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("status",0,metaObject);
        this.setFieldValByName("gmtCreated",new Date(),metaObject);
        this.setFieldValByName("gmtModified",new Date(),metaObject);
    }



    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtModified",new Date(),metaObject);
    }
}
